package P1200;

import java.util.Scanner;


/**
 * @author: zhouyang
 * @descrpition: 1.偶数位的回文数一定不是质数 除了11
 * @time: 2019-10-10 16:59
 */
public class P1217_回文质数 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int left = scanner.nextInt();
        int right = scanner.nextInt();
        scanner.close();
        invoke(left, right);
    }

    private static void invoke(int left, int right) {
        if(left % 2 == 0) ++left;//保证第一个数是奇数
        right = Math.min(right, 9999999);//大了就不可能
        for (int i = left; i <= right; i = i + 2)//枚举每一个奇数
        {
            if (!checkLimit(i)) continue;
            if (!isPalindromes(i)) continue;
            if (!isPrime(i)) continue;
            System.out.println(i);
        }
    }

    private static boolean isPrime(int n) {
        int sqrt = (int) Math.sqrt((double) (n));
        for (int i = 2; i <= sqrt; ++i) {
            if (n % i == 0) return false;
        }
        return true;
    }

    private static boolean isPalindromes(int n) {
        String s = String.valueOf(n);
        int left = 0, right = s.length() - 1;
        while (left < right) {
            if (s.charAt(left++) != s.charAt(right--)) return false;
        }
        return true;
    }

    private static boolean checkLimit(int n) {
        if ((1000 <= n && n <= 9999) || (100000 <= n && n <= 999999))
            return false;
        return true;
    }
}
